
//recording a conversation 
/*goals for this program are to send chat messages to the server chat client
It should be able to send private messages
It should be ables to create a conversation "channel" or some other method of 
creating a loby of private messages between three or more people. 
It should be able to encrypt all private messages. 
From the chat client there need to be commands to access the storage program
From the chat client there should be commands to save files. 
From the chat client there should be commands to "private message" and create a
conference" */ 
/* the chat server should be able to recieve messages from the client, 
and send them that message to all other clients. 
The Server should be able to Filter through Private messages, and make sure
that none of the provate messages reach an unintented client. 
The server chat client should be able to Filter mature language unless a client 
elects not to be filterd.
The server should filer all outgoing language unless the reciving client has 
also elected to turn off a mature filter. 
*/

//http://www.madwizard.org/programming/tutorials/netcpp/4 very good tuterial over sockets 
//code taken from this website for the purpose of showing winsock, and creation of sockets. 
//http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx
// can provide more information. 


/*Ensure that the build environment refers to the Include, Lib, and Src directories 
of the Microsoft Windows Software Development Kit (SDK) or the earlier 
Platform Software Development Kit (SDK).*/ 
//in order for you to get the program to compile you have to make sure that the linker file includes the winsock libarys.
// in dev c++ you can do this by going to 
//project, project options,parameters, add libary or object, and including the libwinsoc32 to the linker.  
//Ensure that the build environment links to the Winsock Library file Ws2_32.lib. Applications that use Winsock must be 
//linked with the Ws2_32.lib library file. The #pragma comment indicates to the linker that the Ws2_32.lib file is needed.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <iostream>
#include <cstdlib>


#pragma comment(lib, "Ws2_32.lib") //I read that this may automaticly include the library file when compiled, depends on the compiler

using namespace std;

int main() 
{
    cout << "************************************************************\n";
    cout << "// Welcome to The chat, and storage client/server program //\n";
    cout << "//                                                        //\n";
    cout << "************************************************************\n";
        


const int iReqWinsockVer = 2;   // Minimum winsock version required

WSADATA wsaData;// this is the call for winsock

//After this comment is error checking for winsock

int iResult;

// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) 
   {
    printf("WSAStartup failed: %d\n", iResult);
    return 1;
    }
    else
    {
//http://msdn.microsoft.com/en-us/library/windows/desktop/bb530741(v=vs.85).aspx
// link for creating a socket for a Client. You are going to have to compare code from the server
//project to make sure that you are conencting to the same ip, and port. when you bind your socket.  

struct addrinfo *result = NULL,
                *ptr = NULL,
                hints;

ZeroMemory( &hints, sizeof(hints) );
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

#define DEFAULT_PORT "27015"
        
// Resolve the server address and port
iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
if (iResult != 0) 
   {
    printf("getaddrinfo failed: %d\n", iResult);
    WSACleanup();
    return 1;
    }
SOCKET ConnectSocket = INVALID_SOCKET;

// Attempt to connect to the first address returned by
// the call to getaddrinfo
ptr=result;

// Create a SOCKET for connecting to server
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, 
    ptr->ai_protocol);

if (ConnectSocket == INVALID_SOCKET) 
   {
    printf("Error at socket(): %ld\n", WSAGetLastError());
    freeaddrinfo(result);
    WSACleanup();
    return 1;
    }
    
     system("PAUSE");
  return 0;
}

//Below is the default server socket code from windows. 



/*#define DEFAULT_PORT "27015"

struct addrinfo *result = NULL, *ptr = NULL, hints;

ZeroMemory(&hints, sizeof (hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;

// Resolve the local address and port to be used by the server
iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
if (iResult != 0) {
    printf("getaddrinfo failed: %d\n", iResult);
    WSACleanup();
    return 1;
}*/

//first step of this is gooing to be getting the client and the server program to talk to each other. 
//I would use the code so far to create two applications, and see if they run localy on your machine, and then 
//see if they connect localy on your machine. The ip address for your local machine is 10.140.0.1
//This may be different, you can check it yourself by opening cmd, and tryping ipcongig. 
